function BSWindow(parent, config)
{
    var myself = this;
    var config = iif(config, {});
    var parent = parent;
    var mouseLoc = {x: 0, y: 0};
    var mainDiv =  document.createElement('div');

    this.UID = Math.floor(Math.random()*100000);


    mainDiv.id = "bsWindow" + this.UID;

    top[mainDiv.id + "_windowCloseHandler"] = function() {
        return myself.close();
    }

    top[mainDiv.id + "_windowMinimizeHandler"] = function() {
        return myself.minimize();
    }

    parent.appendChild(mainDiv);

    with(mainDiv.style) {
        position  = "absolute";
        left      = iif(config.left, 50) + "px";
        top       = iif(config.top, 100) + "px";
        width     = iif(config.width, 320) + "px";
        height    = iif(config.height, 300) + "px";
        border    = "1px solid black";
        zIndex    = iif(config.zIndex, this.UID);
        backgroundColor = "#ffffff";
        overflow = "hidden";
    }
    mainDiv.innerHTML = "";

    var topDiv =  document.createElement('div');
    topDiv.id = "bsWindowTopDiv" + this.UID;
    mainDiv.appendChild(topDiv);
    with(topDiv.style) {
        position  = "absolute";
        left      = "-1px";
        top       = "-1px";
        width     = iif(config.width, 320) + "px";
        height    = "20px";
        border    = "1px solid black";
        fontFamily = "Arial,sans-serif";
        zIndex    =  iif(config.zIndex, this.UID) + 10;
        fontSize = "7pt";
        backgroundImage = "url("  + BS.path + "img/bar_back.gif)";
        backgroundColor = "#D3DAED";
    }

    var topDivInner = '<b style="float:right;"><a href="#" onclick="' + mainDiv.id + '_windowCloseHandler()"     style="text-decoration:none;font-weight:bold;"><img src="' + BS.path + 'img/close2.gif" border="0"></a></b>';
    topDivInner    += '<b style="float:right;"><a href="#" onclick="' + mainDiv.id + '_windowMinimizeHandler()"  style="text-decoration:none;font-weight:bold;"><img src="' + BS.path + 'img/minimize3.gif" border="0"></a></b>';

    topDivInner +=     '&nbsp;' + iif(config.title, "BS Window") + '</div>';
    topDiv.innerHTML = topDivInner;


    this.append = function(element)
    {
        //alert(mainDiv);
        mainDiv.appendChild(element);
    }

    this.close = function()
    {
        parent.removeChild(mainDiv);
        return true;
    }

    this.minimize = function(bool)
    {
        var how = "";
        if(parseInt(mainDiv.style.height) > 20) {
            mainDiv.style.height = "20px";
            how = "none";
        } else {
            mainDiv.style.height = "300px";
            how = "block";
        }
        return true;
    }

    this.getId = function()
    {
        return mainDiv.id;
    }

    this.getMouseLoc = function()
    {
        return mouseLoc;
    }

    this.onDrag = function() {
        var x = parseInt(mainDiv.style.left);
        var y = parseInt(mainDiv.style.top);
        mainDiv.style.zIndex = Number.MAX_VALUE;
        top.bsOffsetX = bsGlobalMouseLoc.x - x;
        top.bsOffsetY = bsGlobalMouseLoc.y - y;
        top.bsDraggedObject = myself;

        document.onmouseup = function() {
            bsGlobalDrop();
        }
    };

    topDiv.onmousedown = this.onDrag;

    this.onDrop = function() {
        mainDiv.style.zIndex = iif(config.zIndex, this.UID);
    }

    this.getView = function()
    {
        return mainDiv;
    }
    
}
